package com.dmlll.controller;

import com.dmlll.pojo.EmploymentMessage;
import com.dmlll.service.CityService;
import com.dmlll.service.CountyService;
import com.dmlll.service.EmploymentInformationService;
import com.dmlll.service.TownshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class EmploymentInformationController {
    @Autowired
    private EmploymentInformationService employmentInformationService;
    @Autowired
    private CityService cityService;
    @Autowired
    private CountyService countyService;
    @Autowired
    private TownshipService townshipService;

    @RequestMapping("/getEmploymentInformation")
    @ResponseBody
    public Integer getEmploymentInformation(EmploymentMessage employmentMessage){
        if(null!=employmentMessage){
            if(employmentMessage.getId()==null) {
                employmentInformationService.addEmploymentInformation(employmentMessage);
            }else {
                employmentInformationService.updateEmployment(employmentMessage);
            }
            return employmentMessage.getId();
        }
        return 0;
    }
    @RequestMapping("/findEmploymentInformationById")
    @ResponseBody
    public EmploymentMessage findEmploymentInformationById(Integer id){
        EmploymentMessage employmentInformationById = employmentInformationService.findEmploymentInformationById(id);
        return employmentInformationById;
    }
    @RequestMapping("/findCityByName")
    @ResponseBody
    public String findCityByName(String name,String provinceCode){
        return cityService.findCityByName(name,provinceCode);
    }
    @RequestMapping("/findCountyByName")
    @ResponseBody
    public String findCountyByName(String name,String cityCode){
        return countyService.findCountyByName(name,cityCode);
    }
    @RequestMapping("findTownByName")
    @ResponseBody
    public String findTownByName(String name,String countyCode){
        return townshipService.findTownByName(name,countyCode);
    }

}
